define(function () {
    'use strict';

    function ctrl($scope,InfoService,$ionicLoading,$stateParams,CommonService,$filter) {

        $scope.channel = {};
        var funds = $scope.funds = new Array();
        $scope.$on('$ionicView.beforeEnter', function() {
            funds.theme_mark=$stateParams['id'];
            init();
        });

        $scope.doRefresh = function() {
            init().finally(function(){
                $scope.$broadcast('scroll.refreshComplete');
            });
        };

        function init(){
            if(!$scope.items){
                $ionicLoading.show();
            }
            //查询主题信息
            return InfoService.getThemeDetail(funds.theme_mark).then(function(data){
                if(data&&data.relate_type){
                    //根据主题标示查询产品
                    $scope.info= data;
                    InfoService.getProdByTheme(funds.theme_mark,data.relate_type,data.order_rule).then(function(data){
                        if(data){
                            funds = data;
                            for(var i=0;i<funds.length;i++){
                                var fund = funds[i];
                                fund.prod_min_subscribe = $filter('prodMinSubscribe')(CommonService.getMinAmount(fund));
                                $scope.funds.push(fund);
                            }
                        }
                        $ionicLoading.hide();
                    });
                }
            });
        }
    }

    ctrl.$inject = ['$scope','InfoService','$ionicLoading','$stateParams','CommonService','$filter'];
    return ctrl;
});